package com.trendit.openapi.util;

import com.trendit.openapi.result.PrinterAddResultData;
import com.trendit.openapi.param.PrintParam;
import com.trendit.openapi.param.PrintStatusQueryParam;
import com.trendit.openapi.param.PrinterAddParam;
import com.trendit.openapi.param.SnParam;
import com.trendit.openapi.result.*;
import org.springframework.core.ParameterizedTypeReference;

import java.util.List;

public class DaQuApi {

    private static String API_PREFIX = "https://iot-device.trenditiot.com/openapi";

    /**
     * 4、批量添加打印机
     */
    public static ResponseResult<PrinterAddResultData> addPrinterBatch(List<PrinterAddParam> printerList) {
        String url = API_PREFIX + "/addPrinter";
        return DaQuRequestUtils.post(url, printerList, new ParameterizedTypeReference<ResponseResult<PrinterAddResultData>>() {
        });
    }

    /**
     * 9、查询设备状态
     */
    public static ResponseResult<PrinterStatusResultData> getDeviceStatus(String sn) {
        return DaQuRequestUtils.post(API_PREFIX + "/getDeviceStatus", new SnParam(sn), new ParameterizedTypeReference<ResponseResult<PrinterStatusResultData>>() {
        });
    }

    /**
     * 1、请求打印
     */
    public static ResponseResult<PrintRequestResultData> print(PrintParam printParam) {
        return DaQuRequestUtils.post(API_PREFIX + "/print", printParam, new ParameterizedTypeReference<ResponseResult<PrintRequestResultData>>() {
        });
    }

    /**
     * 查询小票打印结果
     */
    public static ResponseResult<PrintStatusData> getPrintStatus(PrintStatusQueryParam printStatusQueryParam) {
        return DaQuRequestUtils.post(API_PREFIX + "/getPrintStatus", printStatusQueryParam, new ParameterizedTypeReference<ResponseResult<PrintStatusData>>() {
        });
    }

    /**
     * 6、解绑打印机
     */
    public static ResponseResult<PrinterUnbindResultData> unbind(List<String> snList) {
        return DaQuRequestUtils.post(API_PREFIX + "/delPrinter", snList, new ParameterizedTypeReference<ResponseResult<PrinterUnbindResultData>>() {
        });
    }


    /**
     * 10、清空设备待打印队列
     */
    public static ResponseResult<CleanQueueResultData> cleanWaitingQueue(String sn) {
        return DaQuRequestUtils.post(API_PREFIX + "/cleanWaitingQueue", new SnParam(sn), new ParameterizedTypeReference<ResponseResult<CleanQueueResultData>>() {
        });
    }


}
